package com.commonlib.downloadmgr.subclass;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.os.Environment;

import com.commonlib.downloadmgr.base.DownloadBaseHelper;
import com.commonlib.downloadmgr.base.DownloadBaseJob;
import com.commonlib.downloadmgr.entity.Entity;

public class DownloadHelper extends DownloadBaseHelper<Entity>{
	private static final String SUFFIX = ".apk";
	private static final String PREFIX = "entity_";

	private static DownloadHelper self;
	/**
	 * prevent to initialize outside
	 */
	private DownloadHelper(){
		
	}
	
	public static DownloadHelper getInstance(){
		if (self == null) {
			self = new DownloadHelper();
		}
		return self;
	};
	
	@Override
	protected String getFileName(DownloadBaseJob<Entity> job) {
		return new StringBuilder(PREFIX).append(job.getEntity().pkgName).toString();
	}

	@Override
	protected String getFileSuffix(DownloadBaseJob<Entity> job) {
		return SUFFIX;
	}

	@Override
	protected File getDownloadDir(Context context, DownloadBaseJob<Entity> job) {
		File retVal = Environment.getExternalStorageDirectory();
	    if( retVal != null ){
	      retVal = new File( retVal.getAbsolutePath() + "/com.commonlib.downloadmgr/download");
	    }	
	    if (retVal != null) {
	    	retVal.mkdirs();
		}
	    return retVal;
	}

	@Override
	public void showNotifcation(DownloadBaseJob<Entity> job) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cancelNotifcation(DownloadBaseJob<Entity> job) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Map<String, String> getHeadParameter() {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("Content-Type", "application/json");
		map.put("TVersion", "9");
		map.put("Phone-Model", "Android Model");
		map.put("ScreenH", "480");
		map.put("ScreenW", "800");
		map.put("IMSI", "");
		map.put("Tuser-Agent", "BoutiqueApp/1.0 channel-2");
		map.put("Android-release", "android 4.0");
		map.put("Load", "unknow");
		return map;
	}
}
